from django.shortcuts import render,render_to_response
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
# Create your views here.
import readExcel	
import json

@csrf_exempt
def post(req):
	print "post"
	if req.method == 'POST':

		searchGunDict = {}

		selectType = req.POST['type']
		itemName = req.POST['gunName']
		print itemName
		print selectType
		if itemName != "":
			if selectType == '1':
				searchGunDict = readExcel.getGunid(itemName,'gun')
			elif selectType == '2':
				searchGunDict = readExcel.getGunid(itemName,'ThrowExplosive')
			elif selectType == '3':
				searchGunDict = readExcel.getRoleid(itemName,'person')
			elif selectType == '4':
				searchGunDict = readExcel.getRoleid(itemName,'monster')
			elif selectType == '5':
				searchGunDict = readExcel.getGunid(itemName,'Metee')
			elif selectType == '6':
				searchGunDict = readExcel.getGunid(itemName,'inventory')

		c = {
		#"data":[5, 20, 40, 10, 10, 100],
		"gunDict": searchGunDict,
		"len": len(searchGunDict),
		'Selecttype': selectType
		#"coats":getAllcoatnum()
		}
		print c
		c = json.dumps(c)
		return HttpResponse(c)
	else:
		return None

@csrf_exempt
def index(req):
	if req.method == 'GET':
		return render_to_response('index.html')
	if req.method == 'POST':
		for key in req.POST:
			print key
			valuelist = req.POST.getlist(key)
			print valuelist[0]

		searchGunDict = {}

		selectType = req.POST['type']
		itemName = req.POST['gunName']

		if itemName != "":
			if selectType == '1':
				searchGunDict = readExcel.getGunid(itemName,'gun')
			elif selectType == '2':
				searchGunDict = readExcel.getGunid(itemName,'ThrowExplosive')
			elif selectType == '3':
				searchGunDict = readExcel.getRoleid(itemName,'person')
			elif selectType == '4':
				searchGunDict = readExcel.getRoleid(itemName,'monster')
			elif selectType == '5':
				searchGunDict = readExcel.getGunid(itemName,'Metee')
			elif selectType == '6':
				searchGunDict = readExcel.getGunid(itemName,'inventory')

		c = {
         #"data":[5, 20, 40, 10, 10, 100],
         "gunDict": searchGunDict,
         "len": len(searchGunDict),
         'type': selectType
         #"coats":getAllcoatnum()
         }
		return render_to_response('index.html',c)


